<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
include("db/connect.php");
$selectprovince="SELECT * FROM province ORDER BY province_name ASC";
$queryprovince=mysql_query($selectprovince);
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="js/jquery.js"></script>
<script>$(document).ready(function() {
    $("#province_id").change(function(){
		if($("#province_id").val()==1234){
			alert("โปรดเลือกจังหวัด");
			$("#amphur_id").html('');
			$("#amphur_id").html("<option value='1234'>โปรดเลือกจังหวัด</option>");
			$("#tambol_id").html('');
			$("#tambol_id").html("<option value='1234'>โปรดเลือกอำเภอ</option>");
			}
			else{
		$.ajax({
			type:"POST",
			url:"test2.php",
			data:"temp="+$("#province_id").val(),
			success: function(msg){
				$("#spaceamphur").html(msg);
				}
			});//ajax
			
			}//else
	});//province change
}); 
/*function amphur*/
function amphur_change(){
		$.ajax({
			type:"POST",
			url:"test3.php",
			data:"temp="+$("#amphur_id").val(),
			success: function(msg){
				$("#spacetambol").html(msg);
				}
			});//ajax
	}//amphurchange
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label for="select">จังหวัด :</label>
    <select name="province_id" id="province_id">
      <option value="1234">โปรดเลือก</option>
      <?php 
	while($resultprovince=mysql_fetch_array($queryprovince)){
		?>
      <option value="<?php echo$resultprovince["province_id"]?>"><?php echo $resultprovince["province_name"]?></option>
      ><?php
        }
	?>
    </select>
  </p>
  <p id="spaceamphur">
    <label for="select3">อำเภอ :</label>
    <select name="amphur_id" id="amphur_id">
    <option>โปรดเลือกจังหวัด</option>
    </select>
  </p>
  <p id="spacetambol"> 
    <label for="select4">ตำบล :</label>
    <select name="tambol_id" id="tambol_id">
    <option>โปรดเลือกอำเภอ</option>
    </select>
  </p>
  <label for="select2"></label>
</form>
</body>
</html>
